﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PMS.ENT;
using PMS.ENT.Report;
using PMS.Utilities;
using PMS.BLL;
using System.IO;
using System.Text;
using System.IO.Compression;
using Ionic.Zip;
using Ionic.Zlib;
using CrystalDecisions.Shared;
using PMS.Hubs;



namespace PMS.Controllers
{
    public class ScheduleController : Controller
    {

        ChatHub chub = new ChatHub();
        #region Manage Schedule

        #region List
        public ActionResult ManageSchedule(int? projectID)
        {
            try
            {
                #region Permission
                //if (Session["UserID"] == null || Utility.IntParse(Session["UserID"]) <= 0)
                //{
                //    return RedirectToAction("Login", "Home");
                //}

                //if (Utility.UserID <= 0 || Utility.RoleID <= 0 || string.IsNullOrWhiteSpace(Utility.Role))
                //{
                //    return RedirectToAction("Login", "Home");
                //}

                #endregion

                #region LoadData
                int page = MvcApplication.pageDefault;
                int pageSize = MvcApplication.pageSizeDefault;
                int totalRecords = 0;
                int userID = 0;
                if (Utility.Role == Role.Teacher.ToString())
                {
                    userID = Utility.UserID;
                }
                ScheduleCollection listProjet = ScheduleBLL.GetScheduleList(string.Empty, projectID ?? 0, 0, userID, string.Empty, ScheduleColumns.ScheduleName.ToString(), OrderDirection.ASC.ToString(), page, pageSize, out totalRecords);

                LoadDataForList(projectID ?? 0, userID, 0);
                #endregion

                #region Pagination and search
                ViewData["ScheduleName"] = string.Empty;
                ViewData["Status"] = "--All--";
                ViewData["IsSearch"] = 0;
                ViewData["OrderBy"] = ScheduleColumns.ScheduleName.ToString();
                ViewData["OrderDirection"] = OrderDirection.ASC.ToString();
                ViewData["Page"] = page;
                ViewData["PageSize"] = pageSize;
                double PageNum = Math.Ceiling((double)totalRecords / pageSize);
                ViewData["PageNum"] = PageNum;
                ViewData["TotalRecord"] = totalRecords;

                if (totalRecords > 0)
                {
                    if (page == PageNum)
                        ViewData["PageInfo"] = string.Format(" {0} - {1} / {2}.", (((page - 1) * pageSize) + 1).ToString(), totalRecords.ToString(), totalRecords.ToString());
                    else
                        ViewData["PageInfo"] = string.Format(" {0} - {1} / {2}.", (((page - 1) * pageSize) + 1).ToString(), (pageSize * page).ToString(), totalRecords.ToString());
                }
                #endregion

                return View(listProjet);
            }
            catch (DataAccessException)
            {
                TempData[PageInfo.Message.ToString()] = "BLM_ERR_Common";
                return RedirectToAction("Error", "Home");
            }
            catch (Exception ex)
            {
                LogBLL.LogEx("BLM_ERR_Common", ex);
                TempData[PageInfo.Message.ToString()] = "BLM_ERR_Common";
                return RedirectToAction("Error", "Home");
            }
        }

        [HttpPost]
        public ActionResult ManageSchedule(int[] scheduleID, string action, int isSearch, string scheduleName, int projectID, int semesterID, int userID, int? groupID, string status, string orderBy, string orderDirection, int page, int pageSize, string url)
        {
            try
            {
                #region Permission
                //if (Session["UserID"] == null || Utility.IntParse(Session["UserID"]) <= 0)
                //{
                //    return RedirectToAction("Login", "Home");
                //}

                //if (Utility.UserID <= 0 || Utility.RoleID <= 0 || string.IsNullOrWhiteSpace(Utility.Role))
                //{
                //    return RedirectToAction("Login", "Home");
                //}

                #endregion

                #region Do Action
                if (action == ActionName.Delete.ToString())
                {
                    if (ScheduleBLL.CheckIsOwnAndDraft(scheduleID, Utility.UserID))
                    {
                        if (ScheduleBLL.DeleteSchedule(Utility.StringParse(scheduleID), Utility.UserID) > 0)
                        {
                            TempData["Message"] = "Success, delete!";
                        }
                    }
                    else
                    {
                        TempData["Message"] = "Error, cannot delete schedules are not yours or in progress!";
                    }
                }
                else if (action == ActionName.Confirm.ToString())
                {
                    if (ScheduleBLL.CheckIsOwnAndDraft(scheduleID, Utility.UserID))
                    {
                        if (ScheduleBLL.ConfirmSchedule(Utility.StringParse(scheduleID), Utility.UserID) > 0)
                        {
                            TempData["Message"] = "Success, confirm!";
                        }
                    }
                    else
                    {
                        TempData["Message"] = "Error, cannot confirm schedules are not yours or already confirm!";
                    }
                }
                else if (action == ActionName.Schedule.ToString())
                {
                    int[] gID = { groupID ?? 0 };
                    if (ScheduleBLL.CheckScheduleStatus(scheduleID, ProjectStatus.Confirm.ToString()) && GroupBLL.CheckGroupStatus(gID, ProjectStatus.Confirm.ToString()))
                    {
                        int result = ScheduleBLL.JoinSchedule(scheduleID[0], groupID ?? 0, Utility.UserID);
                        if (result > 0)
                        {
                            TempData["Message"] = "Success, add schedule to group!";
                            //Notification
                            foreach (var item in NotificationBLL.InsertNotification(Utility.UserID, NotificationType.AddSchedule, Utility.Role, groupID ?? 0, "/Schedule/Upload/" + result, result, 0))
                            {
                                chub.SendNotification(item.Description, item.Link, item.UserID.ToString());
                            }
                            

                        }
                        else if (result == -1)
                        {
                            TempData["Message"] = "Error, already added!";
                        }
                        else
                        {
                            TempData["Message"] = "Error, add schedule to group!";
                        }
                    }
                    else
                    {
                        TempData["Message"] = "Error, schedule or group is not confirm!";
                    }
                }
                else if (action == ActionName.Print.ToString())
                {
                    int id = scheduleID[0];

                    ScheduleENT schedule = ScheduleBLL.GetScheduleByID(id);
                    ScheduleItemCollection listItem = ScheduleItemBLL.GetScheduleItemListByScheduleID(id);

                    ScheduleDetailRPT scheduleRPT = new ScheduleDetailRPT();
                    scheduleRPT.SetDataSource(listItem);


                    scheduleRPT.SetParameterValue("ProjectName", schedule.ProjectName);
                    scheduleRPT.SetParameterValue("Semester", schedule.SemesterName);

                    Stream stream;
                    stream = scheduleRPT.ExportToStream(ExportFormatType.PortableDocFormat);
                    Response.AddHeader("content-dispostion", "attachemnt; filename=ScheduleDetail.pdf");
                    Response.AddHeader("content-type", "application/pdf");

                    stream.Seek(0, System.IO.SeekOrigin.Begin);

                    StreamReader reader = new StreamReader(stream);
                    byte[] fileData = new byte[stream.Length];
                    stream.Read(fileData, 0, (int)stream.Length);

                    Response.AddHeader("Content-Length", stream.Length.ToString());
                    Response.BinaryWrite(fileData);
                    stream.Close();
                    return null;
                }

                #endregion

                #region LoadData
                string sstatus = string.Empty;
                if (status == "--All--")
                {
                    sstatus = string.Empty;
                }
                else
                {
                    sstatus = status;
                }
                int totalRecords = 0;

                ScheduleCollection listProjet = ScheduleBLL.GetScheduleList(scheduleName, projectID, semesterID, userID, sstatus, orderBy, orderDirection, page, pageSize, out totalRecords);

                LoadDataForList(projectID, userID, semesterID);
                #endregion

                #region Pagination
                ViewData["ScheduleName"] = scheduleName;
                ViewData["Status"] = status;
                ViewData["IsSearch"] = isSearch;
                ViewData["OrderBy"] = orderBy;
                ViewData["OrderDirection"] = orderDirection;
                ViewData["Page"] = page;
                ViewData["PageSize"] = pageSize;
                double PageNum = Math.Ceiling((double)totalRecords / pageSize);
                ViewData["PageNum"] = PageNum;
                ViewData["TotalRecord"] = totalRecords;

                if (totalRecords > 0)
                {
                    if (page == PageNum)
                        ViewData["PageInfo"] = string.Format(" {0} - {1} / {2}.", (((page - 1) * pageSize) + 1).ToString(), totalRecords.ToString(), totalRecords.ToString());
                    else
                        ViewData["PageInfo"] = string.Format(" {0} - {1} / {2}.", (((page - 1) * pageSize) + 1).ToString(), (pageSize * page).ToString(), totalRecords.ToString());
                }
                #endregion

                return View(listProjet);
            }
            catch (DataAccessException ex)
            {
                TempData[PageInfo.Message.ToString()] = ex.Message;
                return RedirectToAction("Error", "Home"); ;
            }
            catch (Exception ex)
            {
                LogBLL.LogEx("BLM_ERR_Common", ex);
                TempData[PageInfo.Message.ToString()] = "BLM_ERR_Common";
                return RedirectToAction("Error", "Home");
            }
        }


        #endregion

        #region Add

        public ActionResult AddSchedule()
        {
            try
            {
                #region Permission
                //if (Session["UserID"] == null || Utility.IntParse(Session["UserID"]) <= 0)
                //{
                //    return RedirectToAction("Login", "Home");
                //}

                //if (Utility.UserID <= 0 || Utility.RoleID <= 0 || string.IsNullOrWhiteSpace(Utility.Role))
                //{
                //    return RedirectToAction("Login", "Home");
                //}
                if (Utility.RoleID != 2)
                {
                    return RedirectToAction("Dashboard", "Home");
                }
                #endregion

                #region LoadData

                ScheduleENT schedule = new ScheduleENT
                {
                    Status = ScheduleStatus.Draft.ToString(),
                    ListScheduleItem = new ScheduleItemCollection(),
                };

                LoadData(0, 0);

                ViewData["Action"] = ActionName.Insert.ToString();
                #endregion

                return View("Schedule", schedule);
            }
            catch (DataAccessException)
            {
                TempData[PageInfo.Message.ToString()] = "BLM_ERR_Common";
                return RedirectToAction("Error", "Home");
            }
            catch (Exception ex)
            {
                LogBLL.LogEx("BLM_ERR_Common", ex);
                TempData[PageInfo.Message.ToString()] = "BLM_ERR_Common";
                return RedirectToAction("Error", "Home");
            }
        }

        [HttpPost]
        public ActionResult AddSchedule(ScheduleENT schedule)
        {
            try
            {
                #region Permission
                //if (Session["UserID"] == null || Utility.IntParse(Session["UserID"]) <= 0)
                //{
                //    return RedirectToAction("Login", "Home");
                //}

                //if (Utility.UserID <= 0 || Utility.RoleID <= 0 || string.IsNullOrWhiteSpace(Utility.Role))
                //{
                //    return RedirectToAction("Login", "Home");
                //}
                if (Utility.RoleID != 2)
                {
                    return RedirectToAction("Dashboard", "Home");
                }
                #endregion

                #region Do Action
                schedule.OwnerID = Utility.UserID;
                schedule.CreatedBy = Utility.UserID;
                schedule.UpdateBy = Utility.UserID;
                schedule.Status = ScheduleStatus.Draft.ToString();

                int result = ScheduleBLL.InsertSchedule(schedule);
                if (result > 0)
                {
                    TempData["Message"] = "Success, insert schedule!";
                }
                else if (result == -1)
                {
                    TempData["Message"] = "Error, Schedule name exists!";
                }
                else if (result == -2)
                {
                    TempData["Message"] = "Error, insert timeline!";
                }
                else if (result == -3)
                {
                    TempData["Message"] = "Error, update timeline!";
                }

                #endregion

                #region LoadData

                LoadData(schedule.ProjectID, schedule.SemesterID);


                #endregion

                return RedirectToAction("EditSchedule", new { id = result });
            }
            catch (DataAccessException)
            {
                TempData[PageInfo.Message.ToString()] = "BLM_ERR_Common";
                return RedirectToAction("Error", "Home");
            }
            catch (Exception ex)
            {
                LogBLL.LogEx("BLM_ERR_Common", ex);
                TempData[PageInfo.Message.ToString()] = "BLM_ERR_Common";
                return RedirectToAction("Error", "Home");
            }
        }
        #endregion

        #region Edit Schedule
        public ActionResult EditSchedule(int ID)
        {
            try
            {
                #region Permission
                //if (Session["UserID"] == null || Utility.IntParse(Session["UserID"]) <= 0)
                //{
                //    return RedirectToAction("Login", "Home");
                //}

                //if (Utility.UserID <= 0 || Utility.RoleID <= 0 || string.IsNullOrWhiteSpace(Utility.Role))
                //{
                //    return RedirectToAction("Login", "Home");
                //}
                if (Utility.RoleID != 2)
                {
                    return RedirectToAction("Dashboard", "Home");
                }
                #endregion

                #region LoadData

                int[] scheduleID = { ID };

                if (!ScheduleBLL.CheckIsOwnAndDraft(scheduleID, Utility.UserID))
                {
                    TempData["Message"] = "Cannot edit schedule is not yours or draft!";
                    return RedirectToAction("ManageSchedule");
                }

                ScheduleENT schedule = ScheduleBLL.GetScheduleByID(ID);
                schedule.ListScheduleItem = new ScheduleItemCollection();
                schedule.ListScheduleItem = ScheduleItemBLL.GetScheduleItemListByScheduleID(ID);

                LoadData(schedule.ProjectID, schedule.SemesterID);
                // LoadScheduleView(schedule.ListScheduleItem, ID);

                ViewData["Action"] = ActionName.Update.ToString();
                #endregion

                return View("Schedule", schedule);
            }
            catch (DataAccessException)
            {
                TempData[PageInfo.Message.ToString()] = "BLM_ERR_Common";
                return RedirectToAction("Error", "Home");
            }
            catch (Exception ex)
            {
                LogBLL.LogEx("BLM_ERR_Common", ex);
                TempData[PageInfo.Message.ToString()] = "BLM_ERR_Common";
                return RedirectToAction("Error", "Home");
            }
        }

        [HttpPost]
        public ActionResult EditSchedule(int ID, ScheduleENT schedule)
        {
            try
            {
                #region Permission
                //if (Session["UserID"] == null || Utility.IntParse(Session["UserID"]) <= 0)
                //{
                //    return RedirectToAction("Login", "Home");
                //}

                //if (Utility.UserID <= 0 || Utility.RoleID <= 0 || string.IsNullOrWhiteSpace(Utility.Role))
                //{
                //    return RedirectToAction("Login", "Home");
                //}
                if (Utility.RoleID != 2)
                {
                    return RedirectToAction("Dashboard", "Home");
                }
                #endregion

                #region Do Action
                schedule.OwnerID = Utility.UserID;
                schedule.UpdateBy = Utility.UserID;

                int result = ScheduleBLL.UpdateSchedule(schedule);
                if (result > 0)
                {
                    TempData["Message"] = "Success, Update schedule!";
                }
                else if (result == -1)
                {
                    TempData["Message"] = "Error, Schedule name exists!";
                }

                #endregion

                #region LoadData

                LoadData(schedule.ProjectID, schedule.SemesterID);
                // LoadScheduleView(schedule.ListScheduleItem, ID);
                ViewData["Action"] = ActionName.Update.ToString();

                #endregion

                return View("Schedule", schedule);
            }
            catch (DataAccessException)
            {
                TempData[PageInfo.Message.ToString()] = "BLM_ERR_Common";
                return RedirectToAction("Error", "Home");
            }
            catch (Exception ex)
            {
                LogBLL.LogEx("BLM_ERR_Common", ex);
                TempData[PageInfo.Message.ToString()] = "BLM_ERR_Common";
                return RedirectToAction("Error", "Home");
            }
        }
        #endregion

        #region View Schedule
        public ActionResult ViewSchedule(int ID)
        {
            try
            {
                #region Permission
                //if (Session["UserID"] == null || Utility.IntParse(Session["UserID"]) <= 0)
                //{
                //    return RedirectToAction("Login", "Home");
                //}

                //if (Utility.UserID <= 0 || Utility.RoleID <= 0 || string.IsNullOrWhiteSpace(Utility.Role))
                //{
                //    return RedirectToAction("Login", "Home");
                //}

                #endregion

                #region LoadData

                int[] scheduleID = { ID };



                ScheduleENT schedule = ScheduleBLL.GetScheduleByID(ID);
                schedule.ListScheduleItem = new ScheduleItemCollection();
                schedule.ListScheduleItem = ScheduleItemBLL.GetScheduleItemListByScheduleID(ID);

                LoadData(schedule.ProjectID, schedule.SemesterID);
                // LoadScheduleView(schedule.ListScheduleItem, ID);

                ViewData["Action"] = ActionName.View.ToString();
                #endregion

                return View("Schedule", schedule);
            }
            catch (DataAccessException)
            {
                TempData[PageInfo.Message.ToString()] = "BLM_ERR_Common";
                return RedirectToAction("Error", "Home");
            }
            catch (Exception ex)
            {
                LogBLL.LogEx("BLM_ERR_Common", ex);
                TempData[PageInfo.Message.ToString()] = "BLM_ERR_Common";
                return RedirectToAction("Error", "Home");
            }
        }
        #endregion

        #region Timeline
        public ActionResult TimeLine(int ID)
        {
            try
            {
                LoadScheduleView(ID);
                ViewData["ScheduleID"] = ID;
                return View();
            }
            catch (DataAccessException)
            {
                TempData[PageInfo.Message.ToString()] = "BLM_ERR_Common";
                return RedirectToAction("Error", "Home");
            }
            catch (Exception ex)
            {
                LogBLL.LogEx("BLM_ERR_Common", ex);
                TempData[PageInfo.Message.ToString()] = "BLM_ERR_Common";
                return RedirectToAction("Error", "Home");
            }
        }
        #endregion

        #region LoadData
        public void LoadData(int projectID, int semesterID)
        {
            ViewData["ProjectList"] = new SelectList(ProjectBLL.GetProjectListForCMB(Utility.UserID), ProjectColumns.ProjectID.ToString(), ProjectColumns.ProjectName.ToString(), projectID);
            ViewData["SemesterList"] = new SelectList(SemesterBLL.GetSemesterListForCMB(), SemesterColumns.SemesterID.ToString(), SemesterColumns.SemesterName.ToString(), semesterID);
        }

        public void LoadDataForList(int projectID, int userID, int semesterID)
        {
            ViewData["ProjectList"] = new SelectList(ProjectBLL.GetProjectListForCMB(Utility.UserID), ProjectColumns.ProjectID.ToString(), ProjectColumns.ProjectName.ToString(), projectID);
            ViewData["UserList"] = new SelectList(UserBLL.GetUserListForCMB(2), UserColumns.UserID.ToString(), UserColumns.FullName.ToString(), userID);
            ViewData["SemesterList"] = new SelectList(SemesterBLL.GetSemesterListForCMB(), SemesterColumns.SemesterID.ToString(), SemesterColumns.SemesterName.ToString(), semesterID);

        }

        public void LoadScheduleView(ScheduleItemCollection listScheduleItem, int ID)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("[");


            for (int i = 0; i < listScheduleItem.Count; i++)
            {
                string s = "{ \"name\": \" " + listScheduleItem[i].Work + " \",\"desc\": \"\",\"values\": [{\"from\": \"/Date(" + JsonDate(listScheduleItem[i].FromDate) + ")/\", \"to\": \"/Date(" + JsonDate(listScheduleItem[i].ToDate) + ")/\", \"desc\": \"Work: " + listScheduleItem[i].Work + "<br/>Percent: " + listScheduleItem[i].Percent + "%<br/>Desc:   " + listScheduleItem[i].Description + " <br/>Date: " + listScheduleItem[i].FromDate.ToString("dd/MM/yyyy") + " to " + listScheduleItem[i].ToDate.ToString("dd/MM/yyyy") + "\", \"label\": \"  " + listScheduleItem[i].Work + "\", \"customClass\": \"ganttRed\"}]}";


                sb.AppendLine(s);
                if (i < listScheduleItem.Count - 1)
                {
                    sb.Append(",");
                }

            }
            sb.AppendLine("]");
            using (StreamWriter outfile = new StreamWriter(Path.Combine(Server.MapPath("~/JsonData"), "jsonData" + ID + ".js")))
            {
                outfile.Write(sb.ToString());
            }

        }

        public void LoadScheduleView(int ID)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("[");

            ScheduleItemCollection listScheduleItem = ScheduleItemBLL.GetScheduleItemListByScheduleID(ID);
            for (int i = 0; i < listScheduleItem.Count; i++)
            {
                string s = "{ \"name\": \" " + listScheduleItem[i].Work + " \",\"desc\": \"\",\"values\": [{\"from\": \"/Date(" + JsonDate(listScheduleItem[i].FromDate) + ")/\", \"to\": \"/Date(" + JsonDate(listScheduleItem[i].ToDate) + ")/\", \"desc\": \"Work: " + listScheduleItem[i].Work + "<br/>Percent: " + listScheduleItem[i].Percent + "%<br/>Desc:   " + listScheduleItem[i].Description + " <br/>Date: " + listScheduleItem[i].FromDate.ToString("dd/MM/yyyy") + " to " + listScheduleItem[i].ToDate.ToString("dd/MM/yyyy") + "\", \"label\": \"  " + listScheduleItem[i].Work + "\", \"customClass\": \"ganttRed\"}]}";


                sb.AppendLine(s);
                if (i < listScheduleItem.Count - 1)
                {
                    sb.Append(",");
                }

            }
            sb.AppendLine("]");
            using (StreamWriter outfile = new StreamWriter(Path.Combine(Server.MapPath("~/JsonData"), "jsonData" + ID + ".js")))
            {
                outfile.Write(sb.ToString());
            }

        }
        #endregion

        #endregion

        #region Manage Progress

        #region List
        public ActionResult ManageProgress()
        {
            try
            {
                #region Permission
                //if (Session["UserID"] == null || Utility.IntParse(Session["UserID"]) <= 0)
                //{
                //    return RedirectToAction("Login", "Home");
                //}

                //if (Utility.UserID <= 0 || Utility.RoleID <= 0 || string.IsNullOrWhiteSpace(Utility.Role))
                //{
                //    return RedirectToAction("Login", "Home");
                //}

                #endregion

                #region LoadData
                int page = MvcApplication.pageDefault;
                int pageSize = MvcApplication.pageSizeDefault;
                int totalRecords = 0;

                ProgressCollection listProjet = ProgressBLL.GetProgressList(Utility.Role, Utility.UserID, 0, 0, 0, 0, ProgressColumns.ProjectName.ToString(), OrderDirection.ASC.ToString(), page, pageSize, out totalRecords);

                LoadDataForProgressList(0, 0, 0, 0);
                #endregion

                #region Pagination and search
                ViewData["ProgressName"] = string.Empty;
                ViewData["Status"] = string.Empty;
                ViewData["IsSearch"] = 0;
                ViewData["OrderBy"] = ProgressColumns.ProjectName.ToString();
                ViewData["OrderDirection"] = OrderDirection.ASC.ToString();
                ViewData["Page"] = page;
                ViewData["PageSize"] = pageSize;
                double PageNum = Math.Ceiling((double)totalRecords / pageSize);
                ViewData["PageNum"] = PageNum;
                ViewData["TotalRecord"] = totalRecords;

                if (totalRecords > 0)
                {
                    if (page == PageNum)
                        ViewData["PageInfo"] = string.Format(" {0} - {1} / {2}.", (((page - 1) * pageSize) + 1).ToString(), totalRecords.ToString(), totalRecords.ToString());
                    else
                        ViewData["PageInfo"] = string.Format(" {0} - {1} / {2}.", (((page - 1) * pageSize) + 1).ToString(), (pageSize * page).ToString(), totalRecords.ToString());
                }
                #endregion

                return View(listProjet);
            }
            catch (DataAccessException)
            {
                TempData[PageInfo.Message.ToString()] = "BLM_ERR_Common";
                return RedirectToAction("Error", "Home");
            }
            catch (Exception ex)
            {
                LogBLL.LogEx("BLM_ERR_Common", ex);
                TempData[PageInfo.Message.ToString()] = "BLM_ERR_Common";
                return RedirectToAction("Error", "Home");
            }
        }

        [HttpPost]
        public ActionResult ManageProgress(int[] progressID, int isSearch, int projectID, int semesterID, int groupID, int scheduleID, string orderBy, string orderDirection, int page, int pageSize)
        {
            try
            {
                #region Permission
                //if (Session["UserID"] == null || Utility.IntParse(Session["UserID"]) <= 0)
                //{
                //    return RedirectToAction("Login", "Home");
                //}

                //if (Utility.UserID <= 0 || Utility.RoleID <= 0 || string.IsNullOrWhiteSpace(Utility.Role))
                //{
                //    return RedirectToAction("Login", "Home");
                //}

                #endregion

                #region LoadData
                int totalRecords = 0;

                ProgressCollection listProjet = ProgressBLL.GetProgressList(Utility.Role, Utility.UserID, projectID, semesterID, scheduleID, groupID, orderBy, orderDirection, page, pageSize, out totalRecords);

                LoadDataForProgressList(projectID, scheduleID, groupID, semesterID);
                #endregion

                #region Pagination
                ViewData["IsSearch"] = isSearch;
                ViewData["OrderBy"] = orderBy;
                ViewData["OrderDirection"] = orderDirection;
                ViewData["Page"] = page;
                ViewData["PageSize"] = pageSize;
                double PageNum = Math.Ceiling((double)totalRecords / pageSize);
                ViewData["PageNum"] = PageNum;
                ViewData["TotalRecord"] = totalRecords;

                if (totalRecords > 0)
                {
                    if (page == PageNum)
                        ViewData["PageInfo"] = string.Format(" {0} - {1} / {2}.", (((page - 1) * pageSize) + 1).ToString(), totalRecords.ToString(), totalRecords.ToString());
                    else
                        ViewData["PageInfo"] = string.Format(" {0} - {1} / {2}.", (((page - 1) * pageSize) + 1).ToString(), (pageSize * page).ToString(), totalRecords.ToString());
                }
                #endregion

                return View(listProjet);
            }
            catch (DataAccessException ex)
            {
                TempData[PageInfo.Message.ToString()] = ex.Message;
                return RedirectToAction("Error", "Home"); ;
            }
            catch (Exception ex)
            {
                LogBLL.LogEx("BLM_ERR_Common", ex);
                TempData[PageInfo.Message.ToString()] = "BLM_ERR_Common";
                return RedirectToAction("Error", "Home");
            }
        }

        #endregion

        #region Upload

        public ActionResult Upload(int ID)
        {
            try
            {
                #region Permission
                //if (Session["UserID"] == null || Utility.IntParse(Session["UserID"]) <= 0)
                //{
                //    return RedirectToAction("Login", "Home");
                //}

                //if (Utility.UserID <= 0 || Utility.RoleID <= 0 || string.IsNullOrWhiteSpace(Utility.Role))
                //{
                //    return RedirectToAction("Login", "Home");
                //}

                #endregion

                #region LoadData
                int groupID = 0;
                int projectOwnerID = 0;
                int task = 0;
                decimal percent = 0;
                decimal total = 0;
                ScheduleItemCollection listScheduleItem = ScheduleItemBLL.GetScheduleItemListByScheduleGroupID(ID, out groupID, out projectOwnerID, out task, out percent, out total);

                UserGroupCollection listusergroup = UserGroupBLL.GetUserGroupListByGroupID(groupID);
                UserGroupENT usergroup = new UserGroupENT();
                usergroup.IsDeleteFile = false;
                usergroup.IsUploadFile = false;
                if (Utility.RoleID == 3)
                {
                    usergroup = listusergroup.Where(d => d.UserID == Utility.UserID).First();
                }
                LoadDataForUpLoad(listScheduleItem);

                ViewData["ScheduleGroupID"] = ID;
                ViewData["DeletePer"] = usergroup.IsDeleteFile;
                ViewData["UploadPer"] = usergroup.IsUploadFile;
                ViewData["Task"] = task;
                ViewData["Percent"] = percent.ToNumberString();
                ViewData["Total"] = total.ToNumberString();
                ViewData["GroupID"] = groupID;
                ViewData["ProjectOwnerID"] = projectOwnerID;
                ViewData["Action"] = ActionName.Upload.ToString();
                #endregion

                return View("Progress", listScheduleItem);
            }
            catch (DataAccessException)
            {
                TempData[PageInfo.Message.ToString()] = "BLM_ERR_Common";
                return RedirectToAction("Error", "Home");
            }
            catch (Exception ex)
            {
                LogBLL.LogEx("BLM_ERR_Common", ex);
                TempData[PageInfo.Message.ToString()] = "BLM_ERR_Common";
                return RedirectToAction("Error", "Home");
            }
        }

        #endregion

        #region LoadData


        public void LoadDataForProgressList(int projectID, int scheduleID, int groupID, int semesterID)
        {
            ViewData["ProjectList"] = new SelectList(ProjectBLL.GetProjectListForCMB(0), ProjectColumns.ProjectID.ToString(), ProjectColumns.ProjectName.ToString(), projectID);
            ViewData["ScheduleList"] = new SelectList(ScheduleBLL.GetScheduleListForCMB(0, projectID, semesterID), ScheduleColumns.ScheduleID.ToString(), ScheduleColumns.ScheduleName.ToString(), scheduleID);
            ViewData["GroupList"] = new SelectList(GroupBLL.GetGroupListForCMB(0, projectID), GroupColumns.GroupID.ToString(), GroupColumns.GroupName.ToString(), groupID);
            ViewData["SemesterList"] = new SelectList(SemesterBLL.GetSemesterListForCMB(), SemesterColumns.SemesterID.ToString(), SemesterColumns.SemesterName.ToString(), semesterID);

        }

        public void LoadDataForUpLoad(ScheduleItemCollection listScheduleItem)
        {
            List<MarkENT> listMark = new List<MarkENT>();

            listMark.Add(new MarkENT { Name = "", Value = 0 });
            listMark.Add(new MarkENT { Name = "1", Value = 1 });
            listMark.Add(new MarkENT { Name = "2", Value = 2 });
            listMark.Add(new MarkENT { Name = "3", Value = 3 });
            listMark.Add(new MarkENT { Name = "4", Value = 4 });
            listMark.Add(new MarkENT { Name = "5", Value = 5 });
            listMark.Add(new MarkENT { Name = "6", Value = 6 });
            listMark.Add(new MarkENT { Name = "7", Value = 7 });
            listMark.Add(new MarkENT { Name = "8", Value = 8 });
            listMark.Add(new MarkENT { Name = "9", Value = 9 });
            listMark.Add(new MarkENT { Name = "10", Value = 10 });

            for (int i = 0; i < listScheduleItem.Count; i++)
            {
                int value = Convert.ToInt32(listScheduleItem[i].Mark);
                ViewData["ListMark" + i] = new SelectList(listMark, MarkColumns.Value.ToString(), MarkColumns.Name.ToString(), value);
            }

        }
        #endregion

        #endregion

        #region Ajax

        #region Group
        public JsonResult GetGroupByScheduleID(int? ID)
        {
            try
            {
                GroupCollection listGroup = GroupBLL.GetGroupListByScheduleIDForCMB(ID ?? 0, Utility.semesterID);
                return Json(new { ListGroup = listGroup }, JsonRequestBehavior.DenyGet);
            }
            catch (Exception)
            {
                return null;
            }
        }

        public JsonResult GetJoinGroupByScheduleID(int? ID)
        {
            try
            {
                GroupCollection listGroup = GroupBLL.GetGroupListJoinByScheduleID(ID ?? 0);
                return Json(new { ListGroup = listGroup }, JsonRequestBehavior.DenyGet);
            }
            catch (Exception)
            {
                return null;
            }
        }
        #endregion

        #region File
        public JsonResult UploadFile(int? groupID, int? scheduleItemID, HttpPostedFileBase qqfile, string schedulegroupid)
        {
            int statementID = 0;
            string filePath = string.Empty;
            FileENT file = new FileENT();
            string fileMD5 = string.Empty;
            string text = string.Empty;
            if (qqfile != null)
            {
                // this works for IE
                CheckStatement(groupID, scheduleItemID, out statementID, out filePath);



                var filename = Path.Combine(filePath, Path.GetFileName(qqfile.FileName));
                qqfile.SaveAs(filename);

                CFileInfo oDetailedFileInfo = new CFileInfo(filename);

                fileMD5 = FileBLL.GetMD5HashFromFile(filename);
                FileInfo fileInfo = new FileInfo(filename);
                InsertFile(oDetailedFileInfo, fileInfo, fileMD5, statementID, filename, out file);

                if (fileInfo.Extension == ".doc" || fileInfo.Extension == ".docx")
                {
                    //split word 
                    text = FileBLL.ReadMsWord(filename);
                    localhost.ProcessFile service = new localhost.ProcessFile();
                    //service.UseDefaultCredentials = false;
                    service.SplitWord(text, fileMD5);
                }
                //Notification
                ScheduleItemENT sche = ScheduleItemBLL.GetScheduleItemByID(scheduleItemID ?? 0);
                ScheduleENT schedule = ScheduleBLL.GetScheduleByID(sche.ScheduleID);

                foreach (var item in NotificationBLL.InsertNotification(Utility.UserID, NotificationType.Upload, Utility.Role, groupID ?? 0, "/Schedule/Upload/" + schedulegroupid, schedule.ProjectID, scheduleItemID ?? 0))
                {
                    chub.SendNotification(item.Description, item.Link, item.UserID.ToString());
                }
                

                return Json(new { success = true, statementID = statementID, Name = file.FileName, fileInfo = file }, "text/plain");
            }
            else
            {
                // this works for Firefox, Chrome
                var filename = Request["qqfile"];

                if (!string.IsNullOrEmpty(filename))
                {
                    CheckStatement(groupID, scheduleItemID, out statementID, out filePath);

                    filename = Path.Combine(filePath, Path.GetFileName(filename));

                    using (var output = System.IO.File.Create(filename))
                    {
                        Request.InputStream.CopyTo(output);
                    }

                    CFileInfo oDetailedFileInfo = new CFileInfo(filename);

                    fileMD5 = FileBLL.GetMD5HashFromFile(filename);
                    FileInfo fileInfo = new FileInfo(filename);
                    InsertFile(oDetailedFileInfo, fileInfo, fileMD5, statementID, filename, out file);

                    if (fileInfo.Extension == ".doc" || fileInfo.Extension == ".docx")
                    {
                        //Split word
                        text = FileBLL.ReadMsWord(filename);
                        //call webservice
                        localhost.ProcessFile service = new localhost.ProcessFile();
                        service.SplitWord(text, fileMD5);

                    }
                    //Notification
                    ScheduleItemENT sche = ScheduleItemBLL.GetScheduleItemByID(scheduleItemID ?? 0);
                    ScheduleENT schedule = ScheduleBLL.GetScheduleByID(sche.ScheduleID);
                    foreach (var item in NotificationBLL.InsertNotification(Utility.UserID, NotificationType.Upload, Utility.Role, groupID ?? 0, "/Schedule/Upload/" + schedulegroupid, schedule.ProjectID, scheduleItemID ?? 0))
                    {
                        chub.SendNotification(item.Description, item.Link, item.UserID.ToString());
                    }
                    

                    return Json(new { success = true, statementID = statementID, fileInfo = file }, "text/plain");
                }
            }
            return Json(new { success = false });
        }

        public void InsertFile(CFileInfo cFileInfo, FileInfo fileInfo, string fileMD5, int statementID, string filePath, out FileENT file)
        {
            try
            {
                filePath = filePath.Remove(0, filePath.IndexOf("Upload"));
                filePath = @"../../" + filePath.Replace("\\", "/");
                file = new FileENT
                {
                    FileID = 0,
                    ScheduleStatementID = statementID,
                    FileMD5 = fileMD5,
                    FileName = fileInfo.Name,
                    FilePath = filePath,
                    FileSize = fileInfo.Length,
                    CreatedBy = Utility.UserID,
                    UpdateBy = Utility.UserID,
                    Isdeleted = 0,
                    FileAuthor = cFileInfo.FileAuthor,
                    FileCategory = cFileInfo.FileCategory,
                    FileComment = cFileInfo.FileComment,
                    FileCreationDate = cFileInfo.FileCreationDate,
                    FileExtension = cFileInfo.FileExtension,
                    FileModificationDate = cFileInfo.FileModificationDate,
                    FileSubject = cFileInfo.FileSubject,
                    FileTitle = cFileInfo.FileTitle,
                    FileType = cFileInfo.FileType,
                    FileVersion = cFileInfo.FileVersion,

                };
                if (FileBLL.InsertFile(file) <= 0)
                {
                    throw new DataAccessException("BLM_ERR_InsertFile");
                }
            }
            catch (Exception)
            {

                throw;
            }
        }

        public JsonResult DeleteFile(int fileID)
        {
            try
            {
                FileENT file = FileBLL.GetFileByID(fileID);

                if (FileBLL.DeleteFile(fileID.ToString(), Utility.UserID) <= 0)
                {
                    throw new DataAccessException();
                }
                else
                {
                    string filePath = file.FilePath.Replace("../../Upload/", "").Replace("/", "\\");
                    var fileName = Path.Combine(Server.MapPath("~/Upload"), filePath);
                    System.IO.File.Delete(fileName);
                }

                return Json(new { Result = true, Message = "Sucess Delete File!" }, JsonRequestBehavior.DenyGet);
            }
            catch (Exception)
            {

                return Json(new { Result = false, Message = "Error Delete File!" }, JsonRequestBehavior.DenyGet);
            }
        }

        public JsonResult GetFileList(int statementID)
        {
            try
            {
                FileCollection listFile = FileBLL.GetFileListByStatementID(statementID);

                return Json(new { ListFile = listFile });
            }
            catch (Exception)
            {

                throw;
            }
        }



        #endregion

        #region Comment
        public JsonResult GetCommentList(int statementID)
        {
            try
            {
                CommentCollection listComment = CommentBLL.GetCommentListByStatementID(statementID);

                return Json(new { ListComment = listComment });
            }
            catch (Exception)
            {

                throw;
            }
        }

        public JsonResult DeleteComment(int commentID)
        {
            try
            {

                if (CommentBLL.DeleteComment(commentID.ToString(), Utility.UserID) <= 0)
                {
                    throw new DataAccessException();
                }

                return Json(new { Result = true, Message = "Sucess Delete Comment!" }, JsonRequestBehavior.DenyGet);
            }
            catch (Exception)
            {

                return Json(new { Result = false, Message = "Error Delete Comment!" }, JsonRequestBehavior.DenyGet);
            }
        }

        public JsonResult InsertComment(int? groupID, int? scheduleItemID, string text, string schedulegroupid)
        {
            try
            {
                int statementID = 0;

                CheckStatement(groupID, scheduleItemID, out statementID);
                ScheduleItemENT sche = ScheduleItemBLL.GetScheduleItemByID(scheduleItemID ?? 0);
                ScheduleENT schedule = ScheduleBLL.GetScheduleByID(sche.ScheduleID);




                CommentENT comment = new CommentENT
                {
                    CommentID = 0,
                    ScheduleStatementID = statementID,
                    OwnerID = Utility.UserID,
                    Owner = Utility.UserName,
                    Text = text,
                    CreatedBy = Utility.UserID,
                    UpdateBy = Utility.UserID,
                    Isdeleted = 0,
                    StrCreatedDate = DateTime.Today.ToString("dd/MM/yyyy")
                };
                int commentID = CommentBLL.InsertComment(comment);
                if (commentID <= 0)
                {
                    throw new DataAccessException("BLM_ERR_InsertComment");
                }
                else
                {
                    comment.CommentID = commentID;


                }

                foreach (var item in NotificationBLL.InsertNotification(Utility.UserID, NotificationType.Comment, Utility.Role, groupID ?? 0, "/Schedule/Upload/" + schedulegroupid, schedule.ProjectID, scheduleItemID ?? 0))
                {
                    chub.SendNotification(item.Description, item.Link, item.UserID.ToString());
                }
                return Json(new { Result = true, Message = "Sucess Insert Comment!", Comment = comment }, JsonRequestBehavior.DenyGet);
            }
            catch (Exception)
            {

                return Json(new { Result = false, Message = "Error Insert Comment!" }, JsonRequestBehavior.DenyGet);
            }
        }
        #endregion

        #region Check
        public void CheckStatement(int? groupID, int? scheduleItemID, out int statementID, out string filePath)
        {
            try
            {
                filePath = Server.MapPath("~/Upload");
                int scheduleID = 0;
                //Check Exists Statement
                ScheduleStatementENT scheduleStatement = ScheduleStatementBLL.GetScheduleStatementByGroupAndScheduleItem(groupID ?? 0, scheduleItemID ?? 0, out scheduleID);

                //If not Exists Statement then insert
                if (scheduleStatement == null || scheduleStatement.ScheduleStatementID <= 0)
                {
                    scheduleStatement =
                        new ScheduleStatementENT
                        {
                            ScheduleItemID = scheduleItemID ?? 0,
                            GroupID = groupID ?? 0,
                            CreatedBy = Utility.UserID,
                            UpdateBy = Utility.UserID,
                            Isdeleted = 0,
                        };

                    statementID = ScheduleStatementBLL.InsertScheduleStatement(scheduleStatement);
                    if (statementID <= 0)
                    {
                        throw new DataAccessException("BLM_ERR_InsertScheduleStatement");
                    }
                }
                else
                {
                    statementID = scheduleStatement.ScheduleStatementID;
                }

                //Create Path (Upload/ScheduleID/GroupID/StatementID)
                filePath = Path.Combine(Server.MapPath("~/Upload"), scheduleID.ToString(), scheduleStatement.GroupID.ToString(), statementID.ToString());

                if (!Directory.Exists(filePath))
                {
                    Directory.CreateDirectory(filePath);
                }
            }
            catch (Exception)
            {

                throw;
            }
        }

        public void CheckStatement(int? groupID, int? scheduleItemID, out int statementID)
        {
            try
            {
                int scheduleID = 0;

                //Check Exists Statement
                ScheduleStatementENT scheduleStatement = ScheduleStatementBLL.GetScheduleStatementByGroupAndScheduleItem(groupID ?? 0, scheduleItemID ?? 0, out scheduleID);

                //If not Exists Statement then insert
                if (scheduleStatement == null || scheduleStatement.ScheduleStatementID <= 0)
                {
                    scheduleStatement =
                        new ScheduleStatementENT
                        {
                            ScheduleItemID = scheduleItemID ?? 0,
                            GroupID = groupID ?? 0,
                            CreatedBy = Utility.UserID,
                            UpdateBy = Utility.UserID,
                            Isdeleted = 0,
                        };

                    statementID = ScheduleStatementBLL.InsertScheduleStatement(scheduleStatement);

                    if (statementID <= 0)
                    {
                        throw new DataAccessException("BLM_ERR_InsertScheduleStatement");
                    }
                }
                else
                {
                    statementID = scheduleStatement.ScheduleStatementID;

                }

            }
            catch (Exception)
            {

                throw;
            }
        }

        public void CheckStatement(int? groupID, int? scheduleItemID, decimal mark, out int statementID)
        {
            try
            {
                int scheduleID = 0;
                //Check Exists Statement
                ScheduleStatementENT scheduleStatement = ScheduleStatementBLL.GetScheduleStatementByGroupAndScheduleItem(groupID ?? 0, scheduleItemID ?? 0, out scheduleID);

                //If not Exists Statement then insert
                if (scheduleStatement == null || scheduleStatement.ScheduleStatementID <= 0)
                {
                    scheduleStatement =
                        new ScheduleStatementENT
                        {
                            ScheduleItemID = scheduleItemID ?? 0,
                            GroupID = groupID ?? 0,
                            Mark = mark,
                            CreatedBy = Utility.UserID,
                            UpdateBy = Utility.UserID,
                            Isdeleted = 0,
                        };

                    statementID = ScheduleStatementBLL.InsertScheduleStatement(scheduleStatement);
                    if (statementID <= 0)
                    {
                        throw new DataAccessException("BLM_ERR_InsertScheduleStatement");
                    }
                }
                else
                {
                    scheduleStatement.Mark = mark;
                    statementID = ScheduleStatementBLL.UpdateScheduleStatement(scheduleStatement);
                    if (statementID <= 0)
                    {
                        throw new DataAccessException("BLM_ERR_UpdateScheduleStatement");
                    }
                }

            }
            catch (Exception)
            {

                throw;
            }
        }
        #endregion

        #region Mark
        public JsonResult Mark(int? groupID, int? scheduleItemID, decimal mark, string schedulegroupid)
        {
            try
            {
                int statementID = 0;

                CheckStatement(groupID, scheduleItemID, mark, out statementID);
                //Notification
                ScheduleItemENT sche = ScheduleItemBLL.GetScheduleItemByID(scheduleItemID ?? 0);
                ScheduleENT schedule = ScheduleBLL.GetScheduleByID(sche.ScheduleID);
                foreach (var item in NotificationBLL.InsertNotification(Utility.UserID, NotificationType.Mark, Utility.Role, groupID ?? 0, "/Schedule/Upload/" + schedulegroupid, schedule.ProjectID, scheduleItemID ?? 0))
                {
                    chub.SendNotification(item.Description, item.Link, item.UserID.ToString());
                }
                

                return Json(new { Result = true, Message = "Sucess Insert Mark!" }, JsonRequestBehavior.DenyGet);
            }
            catch (Exception)
            {

                return Json(new { Result = false, Message = "Error Insert Mark!" }, JsonRequestBehavior.DenyGet);
            }
        }
        #endregion

        #region Schedule

        public JsonResult ScheduleView(int ID)
        {
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("[");

                ScheduleItemCollection listScheduleItem = ScheduleItemBLL.GetScheduleItemListByScheduleID(ID);

                for (int i = 0; i < listScheduleItem.Count; i++)
                {
                    string s = "{ \"name\": \" " + listScheduleItem[i].Work + " \",\"desc\": \"\",\"values\": [{\"from\": \"/Date(" + JsonDate(listScheduleItem[i].FromDate) + ")/\", \"to\": \"/Date(" + JsonDate(listScheduleItem[i].ToDate) + ")/\", \"desc\": \"Work: " + listScheduleItem[i].Work + "<br/>Percent: " + listScheduleItem[i].Percent + "%<br/>Desc:   " + listScheduleItem[i].Description + " <br/>Date: " + listScheduleItem[i].FromDate.ToString("dd/MM/yyyy") + " to " + listScheduleItem[i].ToDate.ToString("dd/MM/yyyy") + "\", \"label\": \"  " + listScheduleItem[i].Work + "\", \"customClass\": \"ganttRed\"}]}";


                    sb.AppendLine(s);
                    if (i < listScheduleItem.Count - 1)
                    {
                        sb.Append(",");
                    }

                }
                sb.AppendLine("]");
                using (StreamWriter outfile = new StreamWriter(Path.Combine(Server.MapPath("~/JsonData"), "jsonData" + ID + ".js")))
                {
                    outfile.Write(sb.ToString());
                }

                return Json(new { ID = ID }, JsonRequestBehavior.DenyGet);
            }
            catch (Exception)
            {

                return null;
            }
        }

        public double JsonDate(DateTime dt)
        {
            DateTime d1 = new DateTime(1970, 1, 1);
            DateTime d2 = dt.ToUniversalTime();
            TimeSpan ts = new TimeSpan(d2.Ticks - d1.Ticks);
            return ts.TotalMilliseconds;
        }

        public JsonResult CheckIsStart(int ID)
        {
            try
            {
                ScheduleENT schedule = ScheduleBLL.GetScheduleByID(ID);
                if (schedule.StartDate >= DateTime.Today)
                {
                    return Json(new { Result = true, Message = "Schedule has been started!" }, JsonRequestBehavior.DenyGet);
                }
                else
                {
                    return Json(new { Result = false, Message = "" }, JsonRequestBehavior.DenyGet);
                }

            }
            catch (Exception)
            {

                return null;
            }
        }

        public JsonResult RemoveFromGroup(int ID, int groupID)
        {
            try
            {
                int result = ScheduleBLL.UnJoinSchedule(ID, groupID, Utility.UserID);
                if (result > 0)
                {
                    return Json(new { Result = "True", Message = "Succes, remove from group!" }, JsonRequestBehavior.DenyGet);
                }
                else
                {
                    return Json(new { Result = "False", Message = "Error, remove from group!" }, JsonRequestBehavior.DenyGet);
                }
            }
            catch (Exception)
            {

                return null;
            }
        }

        public JsonResult GetScheduleByProjectIDAndSemesterID(int projectID, int semesterID)
        {
            try
            {
                ScheduleCollection listSchedule = ScheduleBLL.GetScheduleListForCMB(0, projectID, semesterID);
                return Json(new { ListSchedule = listSchedule }, JsonRequestBehavior.DenyGet);
            }
            catch (Exception)
            {
                return null;
            }
        }

        #endregion

        #region Semester
        public JsonResult GetSemester(int? ID)
        {
            try
            {
                SemesterENT semester = SemesterBLL.GetSemesterByID(ID ?? 0);
                string startDate = semester.FromDate.ToString("yyyy/MM/dd");
                string endDate = semester.ToDate.ToString("yyyy/MM/dd");
                return Json(new { StartDate = startDate, EndDate = endDate }, JsonRequestBehavior.DenyGet);
            }
            catch (Exception)
            {

                return null;
            }
        }
        #endregion

        #endregion

    }
}
